home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Snippets / StandardGetFolder / TestGetFolder source / Main.c
Encoding:
C/C++ Source or Header  |  1993-08-22  |  1.4 KB  |  58 lines  |  [TEXT/KAHL]

  1. #ifdef SystemSevenOrLater
  2. #undef SystemSevenOrLater
  3. #endif
  4. #define SystemSevenOrLater 1
  5.  
  6. #define kHasFSSpecCalls 0x00000002
  7.  
  8. #include <GestaltEqu.h>
  9. #include <Script.h>
  10. #include <Traps.h>
  11. #include "StandardGetFolder.h"
  12.  
  13. void main (void);
  14.  
  15. void main (void)
  16. {    
  17.     StandardFolderReply    theReply;
  18.     OSErr                theError;
  19.     Str255                testPrompt = {"\pSelect A Folder:"};
  20.     Str255                fileName = {"\pTestFile"};
  21.     FSSpec                newFile;
  22.     Boolean                useFSSpecCalls = false;
  23.     long                result;
  24.  
  25.     MaxApplZone();
  26.     InitGraf(&thePort);
  27.     InitFonts();
  28.     FlushEvents(everyEvent,0);
  29.     InitWindows();
  30.     InitMenus();
  31.     TEInit();
  32.     InitDialogs(NULL);
  33.     InitCursor();
  34.     
  35.     /* Check to see if we can use FSSpec calls */
  36.     
  37.     if (GetOSTrapAddress(_Gestalt) != GetToolTrapAddress(_Unimplemented))
  38.         if ((Gestalt(gestaltFSAttr,&result) == noErr)&&(result&kHasFSSpecCalls))
  39.             useFSSpecCalls = true;
  40.     
  41.     theError = StandardGetFolder (testPrompt,&theReply,NULL);
  42.  
  43.     /* if a folder was selected and no error occurred, create the test file, using FSSpec */
  44.     /* calls if available.                                                                */
  45.     
  46.     if ((theError == noErr)&&(theReply.sfGood))
  47.         {
  48.         if (useFSSpecCalls)
  49.             {
  50.             theError = FSMakeFSSpec(theReply.sfVRefNum,theReply.sfDirID,fileName,&newFile);
  51.             theError = FSpCreate(&newFile,'MSWD','WDBN',smSystemScript);
  52.             }
  53.         else
  54.             HCreate(theReply.sfVRefNum,theReply.sfDirID,fileName,'MSWD','WDBN');
  55.         }
  56. }
  57.  
  58.